using UnityEngine;

public class Gun : MonoBehaviour
{
    public GameObject bullet;

    // 生成子弹的速度 每秒N个
    public float spawnRate;
    private float _timer;

    // Start is called before the first frame update
    void Start()
    {
    }

    // Update is called once per frame
    void Update()
    {
        SpawnBullet();
    }

    void SpawnBullet()
    {
        _timer = _timer + Time.deltaTime;
        if (_timer >= 1f / spawnRate)
        {
            _timer = _timer - 1f / spawnRate;
            Instantiate(bullet, transform.position, transform.rotation);
        }
    }
}